package com.yixing.tech.common.tcp.serialize;

import com.yixing.tech.common.utils.DecimalConvertUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HexMsgEncoder extends MessageToByteEncoder<String> {

    @Override
    protected void encode(ChannelHandlerContext ctx, String s, ByteBuf byteBuf) throws Exception {
        log.info("写入原字符串: {}", s);
        byteBuf.writeBytes(DecimalConvertUtil.hexStrToBinaryStr(s));
    }
}
